// 钱包余额提现页面
var basePage = require('../../../common/BasePage');
var util = require('../../../utils/util');
Page({
    behaviors: [basePage],
    data: {
        /**要提现余额 */
        money: '',
        /**真是姓名 */
        account_name: '',
		price:0,
        type:1,//0:余额提现,1:佣金提现,2:钱包,3:分仓余额
         /**是否可以提交 */
         can_submit:true,
         payType:"weixin",//提现方式 通联bank 微信weixin
         whInfo:{},
         wh_id:1,//钱包提现

    },
	onLoad: function(opt) {
        console.log("opt",opt)
		this.setData({
			type:opt.type
        })
        if(opt.wh_id){
            this.setData({
                wh_id:opt.wh_id
            })
        }
        this.getMoney()
	},
    onShow: function () {
		
    },
	getMoney(){
        var reqData={}
        if(this.data.type==1||this.data.type==2||this.data.type==3){
            reqData.wh_id=this.data.wh_id
        }
		this.request({
		    method: 'get',
            url: this.data.host + '/home/money/tixian',
            data:reqData
		}, res => {
		    console.log("金额",res)
			var price=0
			if(this.data.type==1){
				price=res.data.award
			}else if(this.data.type==2){
				price=res.data.coin
			}else if(this.data.type==3){
                price=res.data.wh_money
            }
			this.setData({
                price:price,
                account_name:res.data.name
			})
		});
	},
    money_ok(e) {
        if(e.detail.value){
            this.setData({
                money: parseFloat(e.detail.value).toFixed(2)
            })
        }
        console.log("确认输入金额", e);
       
    },
    toWithrawal() {
        if (this.data.type==2 && this.data.money > 500) {
            return wx.showToast({
                title: '一次提现金额请勿超过500元',
                icon: 'none'
            })
        }
		
		// if (this.data.money > this.data.price) {
		//     return wx.showToast({
		//         title: '提现金额不能大于可提现金额',
		//         icon: 'none'
		//     })
		// }

        if (!this.data.account_name) {
            return wx.showToast({
                title: '请填写姓名',
                icon: 'none'
            })
        }
        if(!this.data.can_submit){
            return wx.showToast({
              title: '请勿重复提交',
              icon:'none'
            })
        }
        this.data.can_submit=false;
        setTimeout(() => {
            this.data.can_submit=true
        }, 2000);
        //0:余额提现,1:佣金提现,2:钱包,3:分仓余额
        this.data.money= util.replaceStr(this.data.money)
        this.data.account_name= util.replaceStr(this.data.account_name)


        var reqData={}
        if(this.data.type==1||this.data.type==2||this.data.type==3){
            reqData.wh_id=this.data.wh_id
        }
        this.request({
            method: 'POST',
            url: this.data.host + '/home/money/tixian?from=weixin',
            data:{
                money:this.data.money,
                account_name:this.data.account_name,
                type:this.data.type,
                ...reqData
            }
        }, res => {
            wx.showToast({
              title: '申请成功'
            })
            wx.navigateBack({
              delta: 1,
            })
        //    console.log(res);
        });
    },
	toLog(){
		wx.navigateTo({
			url: "/pages/profit/qianbaoLog/index?wh_id="+this.data.wh_id
		})
    },
    toWallet(){
        wx.redirectTo({
          url: '/pages/profit/recharge/recharge?wh_id='+this.data.wh_id,
        })
    }
})